<?php

//------------------------------------------------------------------
// File: events.code.php
// Author: Bryan Frost
// Date Created: 2010-03-25
//
// schedule.code.php codebehind
//------------------------------------------------------------------
	
require_once('dataAccess.php');
require_once('utility.php');
require_once('../classes/Player.class.php');
require_once('../classes/Event.class.php');
require_once('../classes/Team.class.php');
require_once('../classes/Tournament.class.php');


function GenerateScheduleContent()
{
	GenerateAllTournaments();
}

// Show All Tournaments
function GenerateAllTournaments()
{
	// Default registration text
	$registrationText = "(Registration opens here online two weeks before)";
	
	// Registration open text (open registration 2 weeks in advance, close 6pm day b4 tournament)
	$registrationMay22 = "<a href=\"http://www.alkivolleyballassociation.com/register2010-05-22-open.html\">Register Now</a>";
	$registrationMay23 = "<a href=\"http://www.alkivolleyballassociation.com/register2010-05-23-Anovice.html\">Register Now</a>";

	$registrationJune27 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-june-27th-junior-boys-team/\">Boys Register Here</a><br /><a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-june-27th-junior-girls-team/\">Girls Register Here</a>";
	
	$registrationJuly03 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-saturday-july-3rd-doubles-team-openaa/\">Register Now</a>";
	$registrationJuly04 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-july-4th-doubles-team-anovice/\">Register Now</a>";




	
	$registrationJuly31 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-saturday-july-31st-junior-boys-team/\">Boys Register Here</a><br /><a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-saturday-july-31st-junior-girls-team/\">Girls Register Here</a>";
	$registrationAugust01 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-aug-1st-junior-boys-team/\">Boys Register Here</a><br /><a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-aug-1st-junior-girls-team/\">Girls Register Here</a>";

	
	$registrationAugust07 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-saturday-aug-7th-doubles-team-openaa/\">Register Now</a>";
	$registrationAugust08 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-aug-8th-doubles-team-anovice/\">Register Now</a>";

	$registrationAugust28 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-saturday-aug-28th-doubles-team-openaa/\">Register Now</a>";
	$registrationAugust29 = "<a href=\"https://alkivolleyballassociation.wufoo.com/forms/register-sunday-aug-29th-doubles-team-anovice/\">Register Now</a>";

	$registrationSeptember11 = "<a href=\"http://www.alkivolleyball.com/register2010-09-11.html\">Register Now</a>";
	$registrationSeptember12 = "<a href=\"http://www.alkivolleyball.com/register2010-09-12.html\">Register Now</a>";
	





	// Registration closed text (close registration @ 6pm Friday)
	$registrationClosedText = "Registration is now closed, for late registration phone: (206) 427 4989";
	
	$tournamentInProgress = "Tournament in progress!";
	
	// Post Tournament start date text.
	$resultsComingSoonText = "";
	
	// Results text (show results link as soon as they're available)
	$resultsMay22Text = "<a href=\"results.php?tournament=23\">View Results!</a>";
	//$resultsMay23Text = "<a href=\"results.php?tournament=24\">View Results!</a>";
	$resultsMay23Text = "";
	
	
	$resultsJuly3Text = "<a href=\"results.php?tournament=26\">View Results!</a>";
	$resultsAugust7Text = "<a href=\"results.php?tournament=30\">View Results!</a>";

	$resultsAugust28Text = "<a href=\"results.php?tournament=32\">View Results!</a>";


	$resultsSeptember11Text = "<a href=\"results.php?tournament=34\">View Results!</a>";




	$tournamentsDataCollection = Tournament::GetCurrentSeasonTournamentData();
	
	//
	// TODO: GetCurrentSeason()
	//
	//$header  = "Schedule 2010";
	$header = "Schedule 2011";
	
	
	echo '<br />';
	echo '<h3>';
	echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	echo $header;
	echo '</h3>';
	
	echo '<div class="grid">';
	echo '<table cellspacing="0">';
	echo '<col  />';
	echo '<col  />';
	echo '<col  />';
	echo '<col  />';
	echo '<thead>';
	echo '<tr class="headings">';
	echo '<th width="35%">Date</th>';
	echo '<th width="35%">Event</th>';
	echo '<th width="30%">Registration</th>';
	echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
	
	$i = 0;
	$tournamentDate = "";
	$tournamentDateCurrent = "";

	foreach($tournamentsDataCollection as $key => $value)
	{
		$tournamentId =	$tournamentsDataCollection[$key]->GetTournamentId();
		$tournamentDate = FormatDateWithoutYear($tournamentsDataCollection[$key]->GetStartDate());
		
		
		$tournamentIsUSOpenQualifier = $tournamentsDataCollection[$key]->GetIsUSOpenQualifier();
		
		
		if (FormatDateGetDayOfYear($tournamentDate) > (FormatDateGetDayOfYear($tournamentDateCurrent) + 2))
		{
			echo "<tr class=\"alternate-line\">";
			echo "<td colspan=\"3\" class=\"td-height\">&nbsp;</td>";
			echo "</tr>";
		}
		
		$tournamentDateCurrent = $tournamentDate;
		
		$tournamentDay = FormatDateGetDayOfWeek($tournamentsDataCollection[$key]->GetStartDate());
		$eventsCollection =	$tournamentsDataCollection[$key]->GetEventsCollection();
		//$tournamentLink = "<a href=\"results.php?tournament=$tournamentId\">$tournamentDate</a>";
		
		//// Alternate rows have unique css class "alternate"
		//$cssRow = ($i & 1 ? "alternate" : "");
		
		//echo "<tr class=$cssRow>";
		//echo "<tr>";
		

		
		//echo "<td>$tournamentDate<br />($tournamentDay)</td>";
		//echo "<td><div id=\"event-date\">$tournamentDate</div>($tournamentDay)</td>";
		
		
		
		
		$divisionString = "";
		//$teamsString = "";
		//$winnerString = "";
		
		$j = 0;
		foreach ($eventsCollection as $key => $value)
		{
			if ($j == 0)
			{
				$rowClass = "";
				if ($eventsCollection[$key]->GetDivision() == "Juniors")
				{
					$rowClass = "juniors";	
				}
				elseif ($eventsCollection[$key]->GetDivision() == "Open")
				{
					$rowClass = "";	
				}
				else
				{
					$rowClass = "alternate";	
				}
				
				
				if ($tournamentIsUSOpenQualifier == '1')
				{
					// TODO: FIX THIS WORKAROUND
					if($tournamentDate == 'August 07')
					{
						$qualifierForUSOpen = "<br /><br /><span class=\"bold\">Alki Grand</span><br /><img src=\"images/USOpen-icon.gif\" width=\"59\" height=\"30\" alt=\"Beach Volleyball Us Open Qualifier at Alki beach in Seattle.\" /><br />(US Open Qualifier)<br /><br />";
					}
					else
					{
						$qualifierForUSOpen = "<br /><br /><img src=\"images/USOpen-icon.gif\" width=\"59\" height=\"30\" alt=\"Beach Volleyball Us Open Qualifier at Alki beach in Seattle.\" /><br />(US Open Qualifier)<br /><br />";
					}

				}
				else
				{
					$qualifierForUSOpen = "";	
				}
				
				
				
				
				//echo "<tr>";
				echo "<tr class=\"$rowClass\">";
				//echo "<td><div id=\"event-date\">$tournamentDate</div>($tournamentDay)</td>";
				echo "<td><div id=\"event-date\">$tournamentDate</div>($tournamentDay)$qualifierForUSOpen</td>";
			}
			

			
			
			if ($j > 0)
			{
				$divisionString .= "<br />";
				//$teamsString .= "<br />";
				//$winnerString .= "<br />";
			}
				
			$eventId = $eventsCollection[$key]->GetEventId();
			
			
			
			//$eventFormat = $eventsCollection[$key]->GetEventFormat();
			//$eventFormat = $eventsCollection[$key]->GetScheduleEventFormat();
			$eventDivision = $eventsCollection[$key]->GetDivision();
			
			if ($eventDivision == "Open")
			{
				$eventDivision = "Open/AA";	
			}
			elseif ($eventDivision == "A")
			{
				$eventDivision = "A/Novice";	
			}
			
			$eventGender = GetTournamentGenderName($eventsCollection[$key]->GetGenderId());
			
			if ($eventDivision == "Juniors")
			{
				if ($eventGender == "Men's")
				{
					$eventGender = "Boys";
				}
				if ($eventGender == "Women's")
				{
					$eventGender = "Girls";
				}
			}
			elseif ($eventGender == "Coed")
			{
				$eventDivision = "Open, A";
			}
			
			//$eventLink = "<a href=\"results.php?event=$eventId\">$eventFormat</a>";
			//$divisionString .= "$eventLink";
			
			

			
			//$divisionString .= "$eventFormat";
			$divisionString .= "<span class=\"medium\">$eventDivision</span> $eventGender";
			
			
			

			
			//$teamsString .= $eventsCollection[$key]->GetNumberOfTeams();

			//$eventWinner = "";
			//$k = 0;
			
//			$playerCollection = $eventsCollection[$key]->GetWinningTeam()->GetPlayerCollection();
//			foreach ($playerCollection as $key2 => $value)
//			{
//				$eventWinner .= $playerCollection[$key2]->GetFullName();
//				if ($k == 0)
//					$eventWinner .= " & ";
//					
//				$k++;
//			}			
//			$winnerString .= $eventWinner;
			
			$j++;
		}
		
		
		
		
		echo "<td>$divisionString</td>";
//		echo "<td>$teamsString</td>";
//		echo "<td>$winnerString</td>";
		
		// Current Server Time (in PST)
		$currentTime = time();
		
		
		
		
		
		
		
		
		if ($tournamentDate == 'May 22')
		{
//			// Registration open until one day prior @ 6pm.
//			if (time() < strtotime("2010-05-21 19:00:00"))
//			{
//				echo "<td>$registrationMay22</td>";
//			}
//			// Registration escilation ends @ 9am.
//			elseif ($currentTime < strtotime("2010-05-22 10:00:00"))
//			{
//				echo "<td>$registrationClosedText</td>";
//			}
//			// Tournament in progress until 9pm.
//			elseif ($currentTime < strtotime("2010-05-22 22:00:00"))
//			{
//				echo "<td>$tournamentInProgress</td>";
//			}
//			// Results coming Soon
//			// TODO: UPDATE ONCE RESULTS ARE LIVE!
//			else
//			{
//				echo "<td>$resultsComingSoonText</td>";	
//			}

//2011			echo "<td>$resultsMay22Text</td>";
echo "<td>$registrationText</td>";
		}
		elseif ($tournamentDate == 'May 23')
		{			
//			// Registration open until one day prior @ 6pm.
//			if (time() < strtotime("2010-05-22 19:00:00"))
//			{
//				echo "<td>$registrationMay23</td>";
//			}
//			// Registration escilation ends @ 9am.
//			elseif ($currentTime < strtotime("2010-05-23 10:00:00"))
//			{
//				echo "<td>$registrationClosedText</td>";
//			}
//			// Tournament in progress until 9pm.
//			elseif ($currentTime < strtotime("2010-05-23 22:00:00"))
//			{
//				echo "<td>$tournamentInProgress</td>";
//			}
//			// Results coming Soon
//			// TODO: UPDATE ONCE RESULTS ARE LIVE!
//			else
//			{
//				echo "<td>$resultsComingSoonText</td>";	
//			}


			echo "<td>$resultsMay23Text</td>";
			
		}
		


		elseif ($tournamentDate == 'June 27')
		{			
			// Registration open until one day prior @ 6pm.
			if (time() < strtotime("2010-06-26 19:00:00"))
			{
				echo "<td>$registrationJune27</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-06-27 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-06-27 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				echo "<td>$resultsComingSoonText</td>";	
			}


			//echo "<td>$resultsMay23Text</td>";
		}







		elseif ($tournamentDate == 'July 03')
		{			
			// Registration open until one day prior @ 6pm.
			if (time() < strtotime("2010-07-02 19:00:00"))
			{
				echo "<td>$registrationJuly03</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-07-03 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-07-03 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				//echo "<td>$resultsComingSoonText</td>";	
			}


//2011			echo "<td>$resultsJuly3Text</td>";
echo "<td>$registrationText</td>";

		}


		elseif ($tournamentDate == 'July 04')
		{			
			// Registration open until one day prior @ 6pm.
			if (time() < strtotime("2010-07-03 19:00:00"))
			{
				echo "<td>$registrationJuly04</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-07-04 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-07-04 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				echo "<td>$resultsComingSoonText</td>";	
			}


			//echo "<td>$resultsMay23Text</td>";
		}







		
		elseif ($tournamentDate == 'July 31')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-17 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-07-30 19:00:00"))
			if (time() < strtotime("2010-07-30 19:00:00"))
			{
				echo "<td>$registrationJuly31</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-07-31 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-07-31 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
//2011				echo "<td>$resultsComingSoonText</td>";	
			}
echo "<td>$registrationText</td>";

			//echo "<td>$resultsMay23Text</td>";
		}


		elseif ($tournamentDate == 'August 01')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-17 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-07-31 19:00:00"))
			if (time() < strtotime("2010-07-31 19:00:00"))
			{
				echo "<td>$registrationAugust01</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-08-01 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-08-01 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				echo "<td>$resultsComingSoonText</td>";	
			}


			//echo "<td>$resultsMay23Text</td>";
		}

		


		elseif ($tournamentDate == 'August 07')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-24 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-08-06 19:00:00"))
			if (time() < strtotime("2010-08-06 19:00:00"))
			{
				echo "<td>$registrationAugust07</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-08-07 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-08-07 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				//echo "<td>$resultsComingSoonText</td>";	
			}


//2011			echo "<td>$resultsAugust7Text</td>";
echo "<td>$registrationText</td>";

		}

		elseif ($tournamentDate == 'August 08')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-24 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-08-07 19:00:00"))
			if (time() < strtotime("2010-08-07 19:00:00"))
			{
				echo "<td>$registrationAugust08</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-08-08 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-08-08 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				echo "<td>$resultsComingSoonText</td>";	
			}


			//echo "<td>$resultsAugust28Text</td>";
		}










elseif ($tournamentDate == 'August 28')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-24 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-08-07 19:00:00"))
			if (time() < strtotime("2010-08-27 19:00:00"))
			{
				echo "<td>$registrationAugust28</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-08-28 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-08-28 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				//echo "<td>$resultsComingSoonText</td>";	
			}


//2011			echo "<td>$resultsAugust28Text</td>";
echo "<td>$registrationText</td>";

		}

elseif ($tournamentDate == 'August 29')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-24 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-08-07 19:00:00"))
			if (time() < strtotime("2010-08-28 19:00:00"))
			{
				echo "<td>$registrationAugust29</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-08-29 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-08-29 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				echo "<td>$resultsComingSoonText</td>";	
			}


			//echo "<td>$resultsMay23Text</td>";
		}		






	elseif ($tournamentDate == 'September 11')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-24 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-08-07 19:00:00"))
			if (time() < strtotime("2010-09-10 19:00:00"))
			{
				echo "<td>$registrationSeptember11</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-09-11 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-09-11 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				//echo "<td>$resultsComingSoonText</td>";	
			}


			echo "<td>$resultsSeptember11Text</td>";
		}

elseif ($tournamentDate == 'September 12')
		{	
			// Registration opens 2 weeks early @ 12am.
			//if (time() < strtotime("2010-07-24 01:00:00"))
			//{
			//	echo "<td>$registrationText</td>";
			//}	
			// Registration open until one day prior @ 6pm.
			//elseif (time() < strtotime("2010-08-07 19:00:00"))
			if (time() < strtotime("2010-9-11 19:00:00"))
			{
				echo "<td>$registrationSeptember12</td>";
			}
			// Registration escilation ends @ 9am.
			elseif ($currentTime < strtotime("2010-09-12 10:00:00"))
			{
				echo "<td>$registrationClosedText</td>";
			}
			// Tournament in progress until 9pm.
			elseif ($currentTime < strtotime("2010-09-12 22:00:00"))
			{
				echo "<td>$tournamentInProgress</td>";
			}
			// Results coming Soon
			// TODO: UPDATE ONCE RESULTS ARE LIVE!
			else
			{
				echo "<td>$resultsComingSoonText</td>";	
			}


			//echo "<td>$resultsSeptember12Text</td>";
		}		

		










		else
		{
			echo "<td>$registrationText</td>";
		}
		
		echo "</tr>";
		
		$i++;
	}
	
	echo '</tbody>';
	echo '</table> ';
	echo '</div>';
}
	
?>